import { _decorator, Component, Node, Sprite, Label } from 'cc';
import { DataManager } from '../Public/DataManager';
import { PublicFn } from '../Public/PublicFn';
const { ccclass, property } = _decorator;

@ccclass('Prop')
export class Prop extends Component {
    @property([Sprite])
    ChangeSpArr:Sprite[]=[];
    @property([Label])
    propNum:Label[]=[]
    onEnable()
    {
        const {curProp}=DataManager.Instance;
        let str='';
        switch (curProp) {
            case 0:
                str="换牌";
                break;
            case 1:
                str="发牌";
                break;
            case 2:
                str="洗牌";
                break;
            default:
                break;
        }
        PublicFn.Instance.changeImg(`imgs/${str}.文字`,this.ChangeSpArr[0])
        PublicFn.Instance.changeImg(`imgs/${str}小图标`,this.ChangeSpArr[1])
        PublicFn.Instance.changeImg(`imgs/${str}`,this.ChangeSpArr[2])
        PublicFn.Instance.changeImg(`imgs/text${curProp}`,this.ChangeSpArr[3])
    }
    update(deltaTime: number) {
        
    }
    /**返回主页 */
    BacktoMain() {
        this.node.active=false;
        this.node.setPosition(600,0);
    }
    /**获得道具 */
    getProp()
    {
        const {curProp}=DataManager.Instance
        if(DataManager.Instance.propArr[curProp])
        {
            if(DataManager.Instance.propArr[curProp][1]>0)
            {
                console.log('获取成功',)
                DataManager.Instance.propArr[curProp][0]++;
                DataManager.Instance.propArr[curProp][1]--;
                this.propNum.forEach((e,i)=>
                {
                    e.string=`${DataManager.Instance.propArr[i][0]}`;
                })
                this.BacktoMain();
            }
            else
            {
                console.log('已经抵达上限',)
            }
        }
    }
}

